#ifndef __STINGER_UTIL_H__
#define __STINGER_UTIL_H__

#include <chrono>

//获取毫米级时间戳
static std::time_t get_timestamp() {
    std::chrono::time_point<std::chrono::system_clock,std::chrono::milliseconds> tp = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());//获取当前时间点
    std::time_t timestamp =  tp.time_since_epoch().count(); //计算距离1970-1-1,00:00的时间长度
    return timestamp;
}

static uint64_t xor_hash(uint8_t * byte_string, int64_t length) {
    if(length < 0) length = 0;

    uint64_t out = 0;
    uint64_t * byte64 = (uint64_t *)byte_string;
    while(length > 8) {
        length -= 8;
        out ^= *(byte64);
        byte64++;
    }

    if(length > 0) {
        uint64_t last = 0;
        uint8_t * cur = (uint8_t *)&last;
        uint8_t * byte8 = (uint8_t *)byte64;
        while(length > 0) {
            length--;
            *(cur++) = *(byte8++);
        }
        out ^= last;
    }

    /* bob jenkin's 64-bit mix */
    out = (~out) + (out << 21); // out = (out << 21) - out - 1;
    out = out ^ (out >> 24);
    out = (out + (out << 3)) + (out << 8); // out * 265
    out = out ^ (out >> 14);
    out = (out + (out << 2)) + (out << 4); // out * 21
    out = out ^ (out >> 28);
    out = out + (out << 31);

    return out;
}

static int bkdr_hash(char *str)
{
    unsigned int seed = 131; 
    unsigned int hash = 0;
 
    while (*str) {
        hash = hash * seed + (*str++);
    }

    return (hash & 0x7FFFFFFF);
}


#endif